#ifndef FHE_CORE_VARREGISTERER_H
#define FHE_CORE_VARREGISTERER_H

#include <fhe/core/NodeFactory.h>
#include <fhe/core/VarDesc.h>

namespace fhe
{
  namespace core
  {
    class FHE_API VarRegisterer
    {
    public:
      template <typename T, typename V>
      VarRegisterer( const std::string& nodeModule, const std::string& nodeName, const std::string& varName, V (T::*p) )
      {
        IVarDesc::Ptr var( new VarDesc<T,V>( p, varName ) );
        if ( NodeFactory::instance().hasNodeDesc( nodeModule, nodeName ) )
        {
          NodeFactory::instance().getNodeDesc( nodeModule, nodeName )->addVar( var );
        }
        else if ( NodeFactory::instance().hasNodeInterface( nodeModule, nodeName ) )
        {
          NodeFactory::instance().getNodeInterface( nodeModule, nodeName )->addVar( var );
        }
        else
        {
          FHE_ERROR( "unknown node type %s.%s", nodeModule.c_str(), nodeName.c_str() );
        }
      }
    };
    
    #define FHE_VAR( nodeModule, nodeName, var ) ::fhe::core::VarRegisterer fhe_var_registerer_##nodeModule##_##nodeName##_##var( #nodeModule, #nodeName, #var, &nodeName::var );
  }
}

#endif
